from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from pydantic import BaseModel, Field

api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=500)


class WikiInputs(BaseModel):
    query: str = Field(description="用户问题")


tool = WikipediaQueryRun(
    api_wrapper=api_wrapper,
    description="获取维基百科信息",
    name="wiki-tool",
    args_schema=WikiInputs,
)
print(tool.invoke({"query": "langchain教程"}))
